package com.sushi.utils;


import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

import java.util.List;


/**
 * @author wywei
 */
@Slf4j
public class BeanUtil extends BeanUtils {



    /**
     * 对象转换
     */
    public static <T> T convert(Object source, Class<T> target){
        try {
            return JSON.parseObject(JSON.toJSONString(source),target);
        }catch (Exception e){
            log.info("解析出错：{}", e.getMessage());
            return null;
        }
    }

    /**
     * 转换列表
     */
    public static <T> List<T> convert(List<?> source, Class<T> target) {
        try {
            return JSON.parseArray(JSON.toJSONString(source), target);
        }catch (Exception e) {
            log.info("解析出错：{}", e.getMessage());
            return null;
        }
    }




}
